package DataBase;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/*
 * Class that get name of recipe and return cost of recipe by sending query to DB
 */

public class GetCostRecipeByName {

	private String recipeName;
	private String priceRecipe;
	
	public GetCostRecipeByName(String recipe)
	{
		this.recipeName=recipe;
		
	}

	
	public String getPriceRecipe ()
	{
		
        SQLConnection sc=new SQLConnection();
		
		     
        	try {			
        		PreparedStatement ps = sc.getConnection().prepareStatement("SELECT rec.Rcost FROM recipe rec WHERE rec.Rname=?  ;");	

        		ps.setString(1,recipeName);
        		
        		ResultSet rs=ps.executeQuery();	
        		while (rs.next())
        		{
        			
        			priceRecipe=rs.getString(1);
        		}
        		 ps.close();
        		 rs.close();
        		 sc.getConnection().close();
        		} catch (SQLException e) {
        			// TODO Auto-generated catch block
        			e.printStackTrace();
        		}
        	
        		return priceRecipe;
        	
        }
        
       

	}
	
	
